import java.awt.*;

/**
 * package devices
 * Created  on 2020/5/14.
 */
public class Device {
    private GTerm gt;
    private String name;
    private String imagePath;
    private Boolean status;
    private int powerRating;

    public Device(String filepath, String deviceName, int powerRating) {
        this.gt = new GTerm(400, 350);
        this.imagePath = filepath;
        this.name = deviceName;
        this.powerRating = powerRating;
        this.status = false;
        renderOutput();
    }

    /**
     * function to refresh the output of device. e.g, name,power and image.
     */
    public void renderOutput() {
        this.gt.clear();
        this.gt.setXY(0, 0);
        // output the attributes
        this.gt.println(String.format("Name: %s", this.name));
        this.gt.println(String.format("Status: %s", outputStatus()));
        // output power depends on powerRating
        if (this.powerRating <= 0)
            this.gt.println(String.format("Rated power production: %d Watts", Math.abs(this.powerRating)));
        if (this.powerRating > 0)
            this.gt.println(String.format("Rated power consumption: %d Watts", Math.abs(this.powerRating)));
        // add img
        this.gt.setXY(0, 80);
        this.gt.addImageIcon(this.imagePath);
    }


    public String outputStatus() {
        if (this.status)
            return "on";
        else
            return "off";
    }


    @Override
    public String toString() {
        return name;
    }

    public GTerm getGt() {
        return gt;
    }

    public void setGt(GTerm gt) {
        this.gt = gt;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public int getPowerRating() {
        return powerRating;
    }

    public void setPowerRating(int powerRating) {
        this.powerRating = powerRating;
    }

}
